#include <QtGui>

#include "main_widget.h"

CMainWidget::CMainWidget(CPropertiesModel* pConfModel,
		QWidget* pParent) :
	QWidget(pParent),
	mCentralLayout(this),
  mTabWidget(),
	mTabConf(pConfModel),
	mTabComm(),
	mTabLogging(&mTabWidget),
	mConnectionWidget(this)
{
	setupUiElements();
	setupActions();
}

CMainWidget::~CMainWidget()
{
}

CConnectionWidget* CMainWidget::getConnectionWidget()
{
	return &mConnectionWidget;
}

void CMainWidget::clientConnected(QString& pHost, quint16& pPort)
{
	mConnectionWidget.clientConnected(pHost, pPort);
	//mTabLogging.setEnabled(true);
	//mTabComm.setEnabled(true);
}

void CMainWidget::clientDisconnected()
{
	mConnectionWidget.clientDisconnected();
	mTabConf.clientDisconnected();
	//mTabLogging.setEnabled(false);
	//mTabComm.setEnabled(false);
}

void CMainWidget::connectionError()
{
	mConnectionWidget.connectionError();
}

void CMainWidget::startRequested()
{
	mTabLogging.startRequested();
	mTabConf.startRequested();
}

void CMainWidget::configRequested()
{
	mTabConf.configRequested();
}

void CMainWidget::sendConfigRequested(CClientConnection* pConnection)
{
	mTabConf.sendConfigRequested(pConnection);
}

void CMainWidget::infoReceived(ELogLevel& pLogLevel, QString& pInfoMsg)
{
	mTabLogging.infoReceived(pLogLevel, pInfoMsg);
}

void CMainWidget::loadFromFile(const QString& pFilename)
{
	mTabConf.loadFromFile(pFilename);
}

void CMainWidget::saveToFile(const QString& pFilename)
{
	mTabConf.saveToFile(pFilename);
}

void CMainWidget::setupUiElements()
{
	mCentralLayout.addWidget(&mConnectionWidget);
	mCentralLayout.addWidget(&mTabWidget);
	mTabWidget.addTab(&mTabConf, tr("Configuration"));
	mTabWidget.addTab(&mTabComm, tr("Communications"));
	mTabWidget.addTab(&mTabLogging, tr("Logging"));
	mTabWidget.addTab(&mTabDefense, tr("Defense"));

	mTabConf.setEnabled(true);
	//mTabComm.setEnabled(false);
	//mTabLogging.setEnabled(false);

	this->setLayout(&mCentralLayout);
}

void CMainWidget::setupActions()
{
}

